﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using libDAL;
using clsEmployeeList.BUS;
using System.IO;

namespace clsEmployeeList.Forms
{
    public partial class frmEmployeeProfile : Form
    {

        private clsEmpListInterface _BUS;
        private bool bolLoaded = false;
        private string strEmployeeID = string.Empty;
        private bool bolCancel = false;
        private int intCol = 0;


        public frmEmployeeProfile()
        {
            InitializeComponent();
        }

        private void set_ButtonDBImage()
        {
            try
            {
           //     btnDBAccess.Image = Image.FromFile(@"Images/delete_database.png");

                //btnDBAccess.BackgroundImage = System.Drawing.Image.FromFile(@"Images/delete_database.png");

                string path = System.IO.Path.GetFullPath("../../Images/delete_database.png");

                btnDBAccess.BackgroundImage = System.Drawing.Image.FromFile(path);
        }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " libEmployeeList_frmEmployeeProfile_set_ButtonDBImage");
            }
        }
       
        private void frmEmployeeProfile_Load(object sender, EventArgs e)
        {
            try
            {
                dgvEmployeeList.SelectionChanged -= dgvEmployeeList_SelectionChanged;

               

               
                _BUS = new clsEmpListInterface();
                _BUS.set_UnTagAllInUse("UserID"); 

                set_LoadEmployeeList();
                set_DissableTabs();
                set_DissableTBInitialize();
                gbAppAccess.Enabled = false;
                gbEntry.Enabled = false;
                txtPassword.UseSystemPasswordChar = true;
                getset_EmployeeID = string.Empty;

                dgvEmployeeList.ClearSelection();
                rboApps.Checked = true;
                dgvEmployeeList.SelectionChanged += dgvEmployeeList_SelectionChanged;
                set_ButtonDBImage();


               

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " libEmployeeList_frmEmployeeProfile_frmEmployeeProfile_Load");
            }
        }

        private void set_DissableTBInitialize()
        {
            try
            {
                tsbSave.Enabled = false;
                //   tsbDelete.Enabled = false; 
            }
            catch (Exception ex)
            {
            }
        }

        private void set_EnableTBInitialize()
        {
            try
            {
                tsbSave.Enabled = true;
                // tsbDelete.Enabled = true;
            }
            catch (Exception ex)
            {
            }
        }

        private string getset_EmployeeID
        {
            get
            {
                return strEmployeeID;
            }
            set
            {
                strEmployeeID = value;
            }
        }

        private void set_DissableTabs()
        {
            tcEmployee.TabPages[1].Enabled = false;

        }

        private DataGridViewRow get_EmployeeListRows
        {
            get
            {
                return get_EmployeeListRows;
            }
        }

        private void set_LoadEmployeeList()
        {
            try
            {
                if (_BUS.set_EmployeeList() == true)
                {
                    if (set_LoadEmployeeListToGrid(_BUS.get_AllEmployees) == true)
                    {
                        this.bolLoaded = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " libEmployeeList_frmEmployeeProfile_set_LoadEmployeeList");
            }
        }

        private Boolean set_LoadEmployeeListToGrid(DataRow[] drList)
        {
            bool bolStatus = false;
            try
            {
                if (dgvEmployeeList.Rows.Count > 0)
                {
                    dgvEmployeeList.Rows.Clear();
                }

                DataGridViewTextBoxCell[] dgvTbcEmpRec = new DataGridViewTextBoxCell[9];
                DataGridViewRow dgvrEmpInfo;

                for (int intIndex = 0; intIndex < drList.Length; intIndex++)
                {
                    dgvrEmpInfo = new DataGridViewRow();
                    for (int intCol = 0; intCol < 9; intCol++)
                    {
                        dgvTbcEmpRec[intIndex] = new DataGridViewTextBoxCell();
                        dgvTbcEmpRec[intIndex].Value = drList[intIndex][intCol];
                        dgvrEmpInfo.Cells.Add(dgvTbcEmpRec[intIndex]);
                    }
                    dgvEmployeeList.Rows.Add(dgvrEmpInfo);
                    bolStatus = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "libEmployeeList_frmEmployeeProfile_set_LoadEmployeeListToGrid");
            }
            return bolStatus;
        }

        private void frmEmployeeProfile_FormClosing(object sender, FormClosingEventArgs e)
        {
            set_ClearMemoryBUS();
        }

        private void set_ClearMemoryBUS()
        {
            _BUS.set_CleanMemory();
            _BUS = null;
            GC.Collect();
        }

        private int get_EmployeeAccountStatus()
        {
            int intStatus = 0;
            if (rboInactive.Checked == true)
            {
                intStatus = 0;
            }
            else if (rboActive.Checked == true)
            {

                intStatus = 1;
            }
            return intStatus;
        }

        private void dgvEmployeeList_CellEnter(object sender, DataGridViewCellEventArgs e)
        {
            if (bolLoaded == true)
            {
                tcEmployee.TabPages[1].Enabled = true;
            }
        }

        private void dgvEmployeeList_TabIndexChanged(object sender, EventArgs e)
        {
            if (bolLoaded == true)
            {
                tcEmployee.TabPages[1].Enabled = true;
            }
        }

        private void tsbCancel_Click(object sender, EventArgs e)
        {

            dgvEmployeeList.SelectionChanged -= dgvEmployeeList_SelectionChanged;
            dgvApplicationList.Rows.Clear();
            _BUS.set_UnTagAllInUse("UserID");
            
            gbAppAccess.Enabled = false;
            tcEmployee.TabPages[1].Enabled = false;
            gbEntry.Enabled = false;
            
          
            set_DissableTBInitialize();
            set_clearErrorProviders();
            set_ClearEntryFields();
            set_ClearUserProfile();
            set_ClearUserProfile();
            tcEmployee.SelectedIndex = 0;
            set_LoadEmployeeList();
            getset_EmployeeID = string.Empty;
            dgvEmployeeList.ClearSelection();

            dgvEmployeeList.SelectionChanged += dgvEmployeeList_SelectionChanged;
          
            
        }

        private void set_ClearUserProfile()
        {
            _BUS.getset_FirstName = string.Empty;
            _BUS.getset_intUserLevel = 0;
            _BUS.getset_LastName = string.Empty;
            _BUS.getset_MiddleInitial = string.Empty;
            _BUS.getset_strPassword = string.Empty;
            _BUS.getset_strUserName = string.Empty;
            getset_EmployeeID = string.Empty;
        }

        private void set_clearErrorProviders()
        {
            epFirstName.Clear();
            epHQBranch.Clear();
            epLastName.Clear();
            epOldPassword.Clear();
            epRePassword.Clear();
            epUserLevel.Clear();
            epUserName.Clear();
        }

        private void set_ClearEntryFields()
        {
            txtFirstName.Text = string.Empty;
            txtLatName.Text = string.Empty;
            txtMI.Text = string.Empty;
            txtOldPassword.Text = string.Empty;
            txtPassword.Text = string.Empty;
            txtRe_Password.Text = string.Empty;
            txtUserName.Text = string.Empty;
            cboDesignation.SelectedIndex = 0;
            cboHQBranch.SelectedIndex = 0;
            cboUserLevel.SelectedIndex = 0;
        }

        private bool get_SelectedStatus()
        {
            bool bolStatus = false;
            try
            {
                int intSelectedRows = dgvEmployeeList.SelectedRows.Count;
                if (intSelectedRows >= 1)
                {
                    bolStatus = true;
                }
                else
                {
                    MessageBox.Show("Please select specific employee to display other properties.");
                }
            }
            catch (Exception ex)
            {
            }
            return bolStatus;
        }

        private void tcEmployee_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void set_rboAccountStatus()
        {
            if (_BUS.getset_UserAccountStatus == 0)
            {
                rboInactive.Checked = true;
            }
            else
            {
                rboInactive.Checked = false;
            }

            if (_BUS.getset_UserAccountStatus == 1)
            {

                rboActive.Checked = true;
            }
            else
            {
                rboActive.Checked = false;
            }
        
        }

        private void set_UntagUser()
        {
            if (getset_EmployeeID.Trim() != string.Empty)
            {
                _BUS.set_UnTagAllInUse("UserID");
            }
        }

        private void set_EmployeeTextFieldCredentials()
        {
            try
            {
                   string strEmployeeID = string.Empty;
                   strEmployeeID = dgvEmployeeList.CurrentRow.Cells["EmployeeID"].Value.ToString().Trim();

                   set_UntagUser();
                
                    if (_BUS.get_CheckEmployeeOnUse(strEmployeeID,"UserID") == false)
                    {
                        DataRow[] drCredentials = _BUS.get_EmployeeCredentials(strEmployeeID);

                        if (drCredentials.Length > 0)
                        {
                            getset_EmployeeID = string.Empty;
                            txtUserName.Text = _BUS.getset_strUserName;
                            txtPassword.Text = _BUS.getset_strPassword;
                            txtFirstName.Text = _BUS.getset_FirstName;
                            txtLatName.Text = _BUS.getset_LastName;
                            txtMI.Text = _BUS.getset_MiddleInitial;
                            cboUserLevel.SelectedIndex = _BUS.getset_intUserLevel;
                            cboHQBranch.Text = _BUS.getset_Branch;
                            cboDesignation.Text = _BUS.getset_Designation;

                            getset_EmployeeID = strEmployeeID;

                            set_rboAccountStatus();
                            _BUS.get_TagUnTagOnUse(1, "UserID", strEmployeeID);
                            set_LoadAppReportList("Program",string.Empty);
                            //_BUS.set_AppListLoadActual(getset_EmployeeID);
                        }
                     }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " libEmployeeList_frmEmployeeProfile_set_EmployeeTextFieldCredentials");
            }
        }

        private bool get_CheckAppListLoaded()
        {
            bool bolStatus = false;
            if (_BUS.get_checkApplistExists() == false)
            {
                bolStatus = _BUS.get_EmployeeAccessList(getset_EmployeeID);
            }
            else
            {
                bolStatus = true;
            }

            return bolStatus;
        }

       

        private void set_LoadActualAppReportList()
        {
            try
            {
               
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " libEmployeeList_frmEmployeeProfile_set_LoadActualAppReportList");
            }
        }

        private void set_LoadAppReportList(string strType, string strSearch)
        {
            try
            {
                #region declarationdgv
                    DataGridViewRow dgvRow;
                    DataGridViewTextBoxCell dgvtModulename;
                    DataGridViewTextBoxCell dgvtModuleDescription;
                    DataGridViewTextBoxCell dgvtEmployeeID_ar;
                    DataGridViewTextBoxCell dgvtEmployeeAccessID;
                    DataGridViewTextBoxCell dgvtModuleID;
                    DataGridViewTextBoxCell dgvtLastModifiedBy_ar;
                    DataGridViewTextBoxCell dgvtDateTimeInserted_ar;
                    DataGridViewTextBoxCell dgvtDateTimeUpdated_ar;
                    DataGridViewTextBoxCell dgvtHostNameIPAddress_ar;
                    DataGridViewCheckBoxCell dgvcbcAccess;
                    DataGridViewCheckBoxCell dgvcbcModify;
                    DataGridViewCheckBoxCell dgvcbcDelete;
                    DataGridViewCheckBoxCell dgvcbcSave;
            #endregion 

                    DataRow[] drAccess = {};
                    if (get_CheckAppListLoaded() == true && _BUS.set_AppListLoadActual(getset_EmployeeID) == true) 
                    {
                        if (dgvApplicationList.Rows.Count > 0)
                        {
                            dgvApplicationList.Rows.Clear();
                        }

                    #region record selection
                        if (strSearch.Trim() == string.Empty)
                        {
                            drAccess = _BUS.get_AccessTypeReportProgram(strType);
                        }
                        else
                        {
                            drAccess = _BUS.get_AccessTypeReportProgram(strType, strSearch);
                        }
                    #endregion

                    for (int intIndex = 0; intIndex < 50; intIndex++)
                    {

                        #region instantiation

                            dgvtModulename = new DataGridViewTextBoxCell();
                            dgvtModuleDescription = new DataGridViewTextBoxCell();
                            dgvcbcAccess = new DataGridViewCheckBoxCell();
                      
                            dgvtEmployeeID_ar = new DataGridViewTextBoxCell();
                            dgvtEmployeeAccessID = new DataGridViewTextBoxCell();
                            dgvtModuleID = new DataGridViewTextBoxCell();
                            dgvtLastModifiedBy_ar = new DataGridViewTextBoxCell();
                            dgvtDateTimeUpdated_ar = new DataGridViewTextBoxCell();
                            dgvtHostNameIPAddress_ar = new DataGridViewTextBoxCell();
                            dgvtDateTimeInserted_ar = new DataGridViewTextBoxCell();
                        
                            dgvcbcModify = new DataGridViewCheckBoxCell();
                            dgvcbcDelete = new DataGridViewCheckBoxCell();
                            dgvcbcSave = new DataGridViewCheckBoxCell();

                            dgvRow = new DataGridViewRow();
                        #endregion

                        dgvtModulename.Value = drAccess[intIndex]["mdModulename"].ToString().Trim();
                        dgvtModuleDescription.Value = drAccess[intIndex]["mdModuleDescription"].ToString().Trim();

                        #region chk
                            if (drAccess[intIndex].IsNull("eaAccess") == true || 
                                drAccess[intIndex]["eaAccess"].ToString().Trim() == string.Empty ||
                                drAccess[intIndex]["eaAccess"].ToString().Trim() == "0")
                            {
                                dgvcbcAccess.Value = false;
                            }
                            else
                            {
                                dgvcbcAccess.Value = true;
                            }

                            if (drAccess[intIndex].IsNull("eaModify") == true || 
                                drAccess[intIndex]["eaModify"].ToString().Trim() == string.Empty ||
                                drAccess[intIndex]["eaModify"].ToString().Trim() == "0")
                            {
                                dgvcbcModify.Value = false;
                            }
                            else
                            {
                                dgvcbcModify.Value = true;
                            }   

                            if (drAccess[intIndex].IsNull("eaDelete") == true || 
                                drAccess[intIndex]["eaDelete"].ToString().Trim() == string.Empty ||
                                drAccess[intIndex]["eaDelete"].ToString().Trim() == "0")
                            {
                                dgvcbcDelete.Value = false;
                            }
                            else
                            {
                                dgvcbcDelete.Value = true;
                            }

                            if (drAccess[intIndex].IsNull("eaSave") == true ||
                                drAccess[intIndex]["eaSave"].ToString().Trim() == string.Empty ||
                                drAccess[intIndex]["eaSave"].ToString().Trim() == "0")
                            {
                                dgvcbcSave.Value = false;
                            }
                            else
                            {
                                dgvcbcSave.Value = true;
                            }
                        #endregion

                        dgvtEmployeeID_ar.Value = drAccess[intIndex]["EmployeeID_ar"].ToString().Trim();
                        dgvtEmployeeAccessID.Value = drAccess[intIndex]["EmployeeAccessID"].ToString().Trim();
                        dgvtModuleID.Value = drAccess[intIndex]["ModuleID"].ToString().Trim();
                        dgvtLastModifiedBy_ar.Value = drAccess[intIndex]["LastMOdifiedBy_ar"].ToString().Trim();
                        
                        #region Date
                            if (drAccess[intIndex].IsNull("DateTimeInserted") == true || drAccess[intIndex]["DateTimeInserted"].ToString().Trim() == string.Empty)
                            {
                                dgvtDateTimeInserted_ar.Value = DBNull.Value;
                            }
                            else
                            {
                                dgvtDateTimeInserted_ar.Value = drAccess[intIndex]["DateTimeInserted"].ToString().Trim();
                            }

                            if (drAccess[intIndex].IsNull("DateTimeUpdated_ar") == true || drAccess[intIndex]["DateTimeUpdated_ar"].ToString().Trim() == string.Empty)
                            {
                                dgvtDateTimeUpdated_ar.Value = DBNull.Value;
                            }
                            else
                            {
                                dgvtDateTimeUpdated_ar.Value = drAccess[intIndex]["DateTimeUpdated_ar"].ToString().Trim();
                            }
                        #endregion

                        dgvtHostNameIPAddress_ar.Value = drAccess[intIndex]["HostNameIPAddress_ar"].ToString().Trim();
                       
                        dgvRow.Cells.Add(dgvtModulename);
                        dgvRow.Cells.Add(dgvtModuleDescription);
                        dgvRow.Cells.Add(dgvcbcAccess);
                        dgvRow.Cells.Add(dgvcbcModify);
                        dgvRow.Cells.Add(dgvcbcDelete);
                        dgvRow.Cells.Add(dgvcbcSave);
                        dgvRow.Cells.Add(dgvtEmployeeID_ar);
                        dgvRow.Cells.Add(dgvtEmployeeAccessID);
                        dgvRow.Cells.Add(dgvtModuleID);
                        dgvRow.Cells.Add(dgvtLastModifiedBy_ar);
                        dgvRow.Cells.Add(dgvtDateTimeInserted_ar);
                        dgvRow.Cells.Add(dgvtDateTimeUpdated_ar);
                        dgvRow.Cells.Add(dgvtHostNameIPAddress_ar);
                        
                        dgvApplicationList.Rows.Add(dgvRow);
                    }

                    dgvApplicationList.PerformLayout();
                    tsslStatus.Text = "Rows: " + dgvApplicationList.Rows.Count; 
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " libEmployeeList_frmEmployeeProfile_set_LoadAppReportList");
  
            }
        }

        private void tsbEdit_Click(object sender, EventArgs e)
        {
            try
            {
                //if (get_SelectedStatus() == true)
                //{
                //    frmPasswordEntry frmPEntry = new frmPasswordEntry();

                //    DialogResult dgResult = frmPEntry.ShowDialog();
                //    if (dgResult == DialogResult.OK)
                //    {
                //        gbAppAccess.Enabled = true;
                //        gbCredentials.Enabled = true;
                //        txtPassword.Enabled = true;

                //        txtRe_Password.Visible = false;
                //        txtOldPassword.Visible = false; 

                //        gbEntry.Enabled = true;
                //        set_EnableTBInitialize();
                //    }
                //    else
                //    {
                //        gbAppAccess.Enabled = false;
                //        gbCredentials.Enabled = false;
                //        gbEntry.Enabled = false;
                //        txtPassword.Enabled = false;


                //        txtRe_Password.Visible = false;
                //        txtOldPassword.Visible = false;

                //        set_DissableTBInitialize(); 
                //    }
                //}
                //else
                //{
                //    MessageBox.Show("Please select employee profile to continue editing."); 
                //}
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " libEmployeeList_frmEmployeeProfile_tsbEdit_Click");
            }
        }

        private void chkEditPassword_CheckedChanged(object sender, EventArgs e)
        {
            //if (chkEditPassword.Checked == true)
            //{
            //    txtPassword.Enabled = true;
            //    txtRe_Password.Enabled = true;
            //    txtOldPassword.Visible = true;
            //}
            //else
            //{
            //    txtPassword.Enabled = false;
            //    txtRe_Password.Enabled = false;
            //    txtOldPassword.Enabled = false;
            //}
        }

        private void chkShowPassword_CheckedChanged(object sender, EventArgs e)
        {
            if (chkShowPassword.Checked == true)
            {
                txtPassword.UseSystemPasswordChar = false;
            }
            else
            {
                txtPassword.UseSystemPasswordChar = true;
            }
        }

        private string get_NewEmployeeID()
        {
            string strIDPart = DateTime.Now.ToString("MdyyHmss");

            strEmployeeID = txtFirstName.Text.Trim().Substring(0, 3) +
                            txtLatName.Text.Trim().Substring(0, 3) +
                            cboHQBranch.Text.Trim().Substring(0, 4);
            return strEmployeeID;
        }

        private void tsbSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (get_ValidateEmployeeProfile() == true)
                {
                    if (tcEmployee.SelectedIndex == 0)
                    {
                    
                        string strEmployeeID = string.Empty;
                        if (getset_EmployeeID.Trim() == string.Empty)
                        {
                            strEmployeeID = get_NewEmployeeID();
                        }
                        else
                        {
                            strEmployeeID = getset_EmployeeID;
                        }

                        if (_BUS.set_InsertUpdateRecordsUserProfile(strEmployeeID, txtFirstName.Text.Trim(), txtLatName.Text.Trim(),
                                                                    txtMI.Text.Trim(), cboDesignation.Text.Trim(), cboUserLevel.SelectedIndex.ToString(),
                                                                    txtPassword.Text.Trim(), cboHQBranch.Text.Trim(), "lastModifiedby", txtUserName.Text.Trim(), get_EmployeeAccountStatus()) == true)
                        {
                            set_LoadEmployeeList();
                            dgvEmployeeList.ClearSelection();
                            set_ClearEntryFields();
                            getset_EmployeeID = string.Empty;
                        }
                    }
                    else if (tcEmployee.SelectedIndex == 1)
                    {
                      if (_BUS.set_InsertUpdateRecordsUserProfile(strEmployeeID, txtFirstName.Text.Trim(), txtLatName.Text.Trim(),
                                                                    txtMI.Text.Trim(), cboDesignation.Text.Trim(), cboUserLevel.SelectedIndex.ToString(),
                                                                    txtPassword.Text.Trim(), cboHQBranch.Text.Trim(), "lastModifiedby", txtUserName.Text.Trim(), get_EmployeeAccountStatus()) == true)
                        {
                            set_LoadEmployeeList();
                            dgvEmployeeList.ClearSelection();
                            set_ClearEntryFields();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " libEmployeeList_frmEmployeeProfile_tsbSave_Click");
            }
        }

        private bool get_ValidateCredentials()
        {
            bool bolStatus = false;
            try
            {
                bool bolUserName = false;
                bool bolUserLevel = false;
                bool bolPassword = false;
                bool bolrePassword = false;
                bool bolOldPassword = false;

                if (txtUserName.Text.Trim() == string.Empty)
                {
                    epUserName.SetError(txtUserName, "Required Field.");
                }
                else
                {
                    epUserName.Clear();
                    bolUserName = true;
                }

                if (cboUserLevel.Text.Trim() == string.Empty)
                {
                    epUserLevel.SetError(cboUserLevel, "Required Field.");
                }
                else
                {
                    epUserLevel.Clear();
                    bolUserLevel = true;
                }

                 if (bolUserName == true && bolUserLevel == true && bolrePassword == true)
                {
                    bolStatus = true;
                }
            }
            catch (Exception ex)
            {

            }

            return bolStatus;
        }

        private Boolean get_ValidateEmployeeProfile()
        {

            bool bolStatus = false;
            try
            {
                bool bolLastName = true;
                bool bolfirstName = true;
                bool bolHQBranch = true;

                if (txtFirstName.Text.Trim() == string.Empty)
                {
                    epFirstName.SetError(txtFirstName, "epLastName");
                    bolfirstName = false;
                }
                else
                {
                    epFirstName.Clear();
                    bolfirstName = true;
                }


                if (txtLatName.Text.Trim() == string.Empty)
                {
                    epLastName.SetError(txtLatName, "Field Empty.");
                    bolLastName = false;
                }
                else
                {
                    epLastName.Clear();
                    bolLastName = true;
                }

                if (cboHQBranch.Text.Trim() == string.Empty)
                {
                    epHQBranch.SetError(cboHQBranch, "Field Empty.");
                    bolHQBranch = false;
                }
                else
                {
                    epHQBranch.Clear();
                    bolHQBranch = true;
                }

                if (bolfirstName == false || bolLastName == false || bolHQBranch == false)
                {
                    bolStatus = false;
                }
                else
                {
                    bolStatus = true;
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " libEmployeeList_frmEmployeeProfile_get_ValidateEmployeeProfile");
            }
            return bolStatus;
        }

        private void dgvEmployeeList_SelectionChanged(object sender, EventArgs e)
        {
                if (bolLoaded == true)
                {
                    set_EmployeeTextFieldCredentials();
                }
        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void txtSearch_TextChanged(object sender, EventArgs e)
        {
            try
            {
                set_LoadEmployeeListToGrid(_BUS.get_getSpecificEmployees(txtSearch.Text.Trim()));
            }
            catch (Exception ex)
            {
            }
        }

        private void scEmployeeProfile_Panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void tsbNew_Click(object sender, EventArgs e)
        {
            try
            {
                
                gbEntry.Enabled = true;
                getset_EmployeeID = string.Empty;
                gbEntry.Enabled = true;
                txtSearch.Enabled = true;
                set_EnableTBInitialize();

                tcEmployee.TabPages[1].Enabled = false;
                dgvEmployeeList.ClearSelection();
                set_clearErrorProviders();
                set_ClearEntryFields();
                set_ClearUserProfile();
                set_ClearUserProfile();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " libEmployeeList_frmEmployeeProfile_tsbNew_Click");
            }
        }

        private void tcEmployee_Selecting(object sender, TabControlCancelEventArgs e)
        {
            try
            {
                if (tcEmployee.SelectedIndex == 1 && getset_EmployeeID.Trim() != string.Empty)
                {
                    if (get_SelectedStatus() == true)
                    {
                        tcEmployee.TabPages[1].Enabled = true;

                        gbUserAccess.Enabled = false;
                        gbPasswordAccess.Enabled = false;



                        gbRePassword.Visible = false;
                        gbOldPassword.Visible = false;

                        set_EmployeeTextFieldCredentials();
                    }
                    else
                    {
                        e.Cancel = true;
                        // tcEmployee.SelectedIndex = 0;
                        //  MessageBox.Show("Please select specific employee to display other properties.");
                    }
                }
                else if ((tcEmployee.SelectedIndex == 1 || tcEmployee.SelectedIndex == 0) && getset_EmployeeID.Trim() == string.Empty &&
                         tsbSave.Enabled == true && get_ValidateEmployeeProfile() == true)
                {
                    tcEmployee.TabPages[1].Enabled = true;
                    gbAppAccess.Enabled = true;
                    // gbCredentials.Enabled = true;
                    txtPassword.Enabled = false;
                    gbEntry.Enabled = true;
                }
                else if (tcEmployee.SelectedIndex == 1 && get_SelectedStatus() == false)
                {
                    e.Cancel = true;

                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " libEmployeeList_frmEmployeeProfile_tcEmployee_Selecting");
            }
        }

        private void txtFirstName_TextChanged(object sender, EventArgs e)
        {
            try
            {


            }
            catch (Exception ex)
            {

            }
        }

        private void txtFirstName_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (clsGenFunction.get_CheckCharset(e.KeyChar.ToString()) == false)
            {
                e.Handled = true;
            }
        }

        private void txtLatName_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (clsGenFunction.get_CheckCharset(e.KeyChar.ToString()) == false)
            {
                e.Handled = true;
            }
        }

        private void txtMI_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (clsGenFunction.get_CheckCharset(e.KeyChar.ToString()) == false)
            {
                e.Handled = true;
            }
        }

        //private void tsbDelete_Click(object sender, EventArgs e)
        //{
        //    try
        //    {
        //        if (get_SelectedStatus() == true)
        //        {
        //            frmPasswordEntry frmPEntry = new frmPasswordEntry();

        //            DialogResult dgResult = frmPEntry.ShowDialog();
        //            if (dgResult == DialogResult.OK)
        //            {
        //                if (_BUS.set_DeleteRecord(getset_EmployeeID) == true)
        //                {
        //                    set_LoadEmployeeList();
        //                    dgvEmployeeList.ClearSelection();
        //                    set_ClearEntryFields();
        //                }
        //            }
        //        }
        //    }
        //    catch (Exception ex)
        //    {

        //    }
        //}

        private void rbNewPassword_CheckedChanged(object sender, EventArgs e)
        {
            if (rboNewPassword.Checked == true)
            {
                gbPassword.Enabled = true;
                gbRePassword.Visible = true;
                gbOldPassword.Visible = false;
            }
            else if (rboEdit.Checked == true)
            {
                gbOldPassword.Visible = true;
                gbRePassword.Visible = true;
                gbPassword.Enabled = true;
            }
        }

        private void label6_Click(object sender, EventArgs e)
        {

        }

        private void txtPassword_TextChanged(object sender, EventArgs e)
        {

        }

        //private void passwordToolStripMenuItem_Click(object sender, EventArgs e)
        //{
        //    try
        //    {

        //        if (get_SelectedStatus() == true)
        //        {
        //            frmPasswordEntry frmPEntry = new frmPasswordEntry();
        //            DialogResult dgResult = frmPEntry.ShowDialog();
        //            if (dgResult == DialogResult.OK)
        //            {
        //                gbPasswordAccess.Enabled = true;
        //                gbPassword.Enabled = false;
        //                gbRePassword.Visible = false;
        //                gbOldPassword.Visible = false;

        //                rboEdit.Checked = false;
        //                rboNewPassword.Checked = false;
        //                chkShowPassword.Checked = false;
        //                tcEmployee.SelectedIndex = 1;
        //                tsbSave.Enabled = true;
        //            }
        //        }
        //    }
        //    catch (Exception ex)
        //    {
               
        //    }
        //}

        //private void accessToolStripMenuItem_Click(object sender, EventArgs e)
        //{
        //    if (get_SelectedStatus() == true)
        //    {
        //        frmPasswordEntry frmPEntry = new frmPasswordEntry();
        //        DialogResult dgResult = frmPEntry.ShowDialog();
        //        if (dgResult == DialogResult.OK)
        //        {
        //            gbUserAccess.Enabled = true;
        //            tcEmployee.SelectedIndex = 1;
        //            tsbSave.Enabled = true;
        //        }
        //        else
        //        {
        //            gbUserAccess.Enabled = false;
        //        }
        //    }
        //    else
        //    {
        //        gbUserAccess.Enabled = false;
        //    }


        //}

        //private void applicationsAccessToolStripMenuItem_Click(object sender, EventArgs e)
        //{
        //    if (get_SelectedStatus() == true)
        //    {
        //        frmPasswordEntry frmPEntry = new frmPasswordEntry();
        //        DialogResult dgResult = frmPEntry.ShowDialog();
        //        if (dgResult == DialogResult.OK)
        //        {
        //            gbAppAccess.Enabled = true;
        //            tsbSave.Enabled = true;
        //        }
        //        else
        //        {
        //            gbAppAccess.Enabled = false;
        //        }
        //    }
        //    else
        //    {
        //        gbAppAccess.Enabled = false;
        //    }
        //}

        //private void profileToolStripMenuItem_Click(object sender, EventArgs e)
        //{
        //    try
        //    {
        //        if (get_SelectedStatus() == true)
        //        {
        //            frmPasswordEntry frmPEntry = new frmPasswordEntry();
        //            DialogResult dgResult = frmPEntry.ShowDialog();
        //            if (dgResult == DialogResult.OK)
        //            {
        //                tcEmployee.SelectedIndex = 0;
        //                gbEntry.Enabled = true;
        //                tsbSave.Enabled = true;
        //            }
        //            else
        //            {
        //                gbEntry.Enabled = false;
        //            }
        //        }
        //        else
        //        {
        //            gbEntry.Enabled = false;
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        MessageBox.Show(ex.Message + " libEmployeeList_frmEmployeeProfile_profileToolStripMenuItem_Click");
        //    }
        //}

        private void set_StatusApplicationGridReadOnlyTrueFalse()
        {
            if (rboReports.Checked == true)
            {
                for (int intIndex = 3; intIndex <= 5; intIndex++)
                {
                    dgvApplicationList.Columns[intIndex].ReadOnly = true ;
                }
            }
            else
            {
                for (int intIndex = 3; intIndex <= 5; intIndex++)
                {
                    dgvApplicationList.Columns[intIndex].ReadOnly = false;
                }
            }
        }

        private void rboReports_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                set_StatusApplicationGridReadOnlyTrueFalse();
                set_LoadAppReportList("Report",string.Empty);
            }
            catch (Exception ex)
            { 
            }
        }

        private void rboApps_CheckedChanged(object sender, EventArgs e)
        {
            set_StatusApplicationGridReadOnlyTrueFalse();
            set_LoadAppReportList("Program",string.Empty);
        }

        private void txtAppSearch_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (rboReports.Checked == true)
            {
                set_LoadAppReportList("Report", txtAppSearch.Text.Trim());
            }
            else if (rboApps.Checked == true)
            {
                set_LoadAppReportList("Program", txtAppSearch.Text.Trim());
            }

        }

        private void dgvApplicationList_CurrentCellDirtyStateChanged(object sender, EventArgs e)
        {
            
            if (dgvApplicationList.IsCurrentCellDirty)
            {
                dgvApplicationList.CommitEdit(DataGridViewDataErrorContexts.Commit);

                MessageBox.Show(dgvApplicationList.CurrentRow.Cells[2].Value.ToString() + " access 1");
             //   MessageBox.Show("access1 " + intCol.ToString());
                //}
                //else
                //{
                //    MessageBox.Show("Others");
                //}
            }
          

            intCol = 0;
        }

        private void dgvApplicationList_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 2)
            {
                intCol = e.ColumnIndex;
              //  MessageBox.Show("intCol");
            }
            //else
            //{
            //    MessageBox.Show("Others");
            //}
            
        }

        private void scEmployeeProfile_Panel2_Paint(object sender, PaintEventArgs e)
        {

        }

       

        

        
    }
}
